/*
 $License:
    Copyright (C) 2014 InvenSense Corporation, All Rights Reserved.
 $
 */

/******************************************************************************
 *
 * $Id:$
 *
 *****************************************************************************/

/**
 * @defgroup ML_LOAD_DMP
 *
 * @{
 *      @file     ml_load_dmp.c
 *      @brief    functions for writing dmp firmware.
 */
#include <stdio.h>

#undef MPL_LOG_TAG
#define MPL_LOG_TAG "MPL-loaddmp"

#include "ml_load_dmp.h"
#include "log.h"
#include "mlos.h"

#define LOADDMP_LOG MPL_LOGI
#define LOADDMP_LOG MPL_LOGI

#define NUM_LOCAL_KEYS (sizeof(dmpTConfig)/sizeof(dmpTConfig[0]))
#define NUM_LOCAL_KEYS (sizeof(dmpTConfig)/sizeof(dmpTConfig[0]))
#define NUM_LOCAL_KEYS (sizeof(dmpTConfig)/sizeof(dmpTConfig[0]))
#define DMP_CODE_SIZE 2943
#define FIFO_SIZE     1024
#define RESERVED_SIZE 32
#define MEMORY_SIZE   1024*4
#define DMP_SIZE_AVAILABLE (MEMORY_SIZE - FIFO_SIZE - RESERVED_SIZE - DMP_CODE_SIZE)
#if DMP_SIZE_AVAILABLE < 0
#error "DMP image size is larger than available memory"
#endif

static const unsigned char dmpMemory[DMP_CODE_SIZE] = {
    /* bank # 0 */
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x01, 0x0b, 0x10, 0xe4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x0a,
    0x06, 0xb8, 0x81, 0xa1, 0xe1, 0x89, 0xb2, 0x78, 0x37, 0xf8, 0x5a, 0x9c, 0xcf, 0xdd, 0x85, 0x3b,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x01, 0xf0, 0x19, 0x80, 0x40, 0x00, 0x00, 0x00, 0x02, 0xca, 0xe3, 0x09, 0x3e, 0x80, 0x00, 0x00,
    0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
    0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x6e, 0x00, 0x00, 0x06, 0x92, 0x0a, 0x16, 0xc0, 0xdf,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07,
    0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0b, 0x2b, 0x00, 0x00, 0x16, 0x57, 0x00, 0x00, 0x03, 0x59,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0xfa, 0x00, 0x02, 0x6c, 0x1d, 0x36, 0x66, 0x66, 0x66,
    0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x1f, 0xdb, 0xe2, 0xb9, 0x3b, 0x7b, 0x11, 0x7b, 0x32, 0x57, 0x83, 0x7b,
    /* bank # 1 */
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0xeb, 0x85, 0x3f, 0xae, 0x14, 0x7b,
    0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x10, 0x72, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0x00, 0x01, 0x00, 0x06, 0x00, 0x01,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x58, 0x05, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0xff,
    0x08, 0x00, 0x02, 0x00, 0x04, 0x00, 0x01, 0x00, 0x80, 0x00, 0x10, 0x00, 0x20, 0x00, 0x40, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb2, 0x6a, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    /* bank # 2 */
    0x00, 0x00, 0x00, 0x00, 0x01, 0x47, 0xae, 0x14, 0x3e, 0xb8, 0x51, 0xec, 0x00, 0x0f, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x14, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x06, 0x74, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x0e, 0x41, 0x28, 0x14, 0xc5, 0xaf, 0x3e, 0xf2, 0x59, 0xd9, 0x4a, 0x5f, 0xc2, 0x36, 0xd9, 0x51,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x05, 0x00, 0x05,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x1b, 0x00, 0x00, 0x00, 0xd9, 0xe8, 0x3e, 0x30, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x05, 0x00, 0x05,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x05, 0x00, 0x05,
    0xff, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    /* bank # 3 */
    0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x18, 0x74, 0x70,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x10, 0x00, 0x96, 0x00, 0x3c,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x0c, 0xb3, 0x12, 0xb4, 0xcc, 0x0f, 0x1e, 0x1b, 0x51, 0xa0, 0xa3, 0x45, 0xc5, 0xad, 0x1e, 0x16,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x18, 0x85, 0x00, 0x00, 0x40, 0x00,
    0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x67, 0x7d, 0xdf, 0x7e, 0x72, 0x90, 0x2e, 0x55, 0x4c, 0xf6, 0xe6, 0x88,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

    /* bank # 4 */
    0xd8, 0xb0, 0xb5, 0xb9, 0xf3, 0xa6, 0xf8, 0xf9, 0xd1, 0xd9, 0x81, 0x96, 0xf8, 0xf7, 0x3e, 0xd8,
    0xf3, 0xb1, 0x86, 0x96, 0xa3, 0x31, 0xd1, 0xda, 0xf1, 0xff, 0xd8, 0xb9, 0xb1, 0xb4, 0xa7, 0x87,
    0x9d, 0xd0, 0xf7, 0x4a, 0xf3, 0x40, 0xb8, 0xb0, 0xf7, 0xa8, 0x8d, 0x91, 0x6a, 0x8d, 0x90, 0x5f,
    0x98, 0x4a, 0xb9, 0xf2, 0xa6, 0xd0, 0xf8, 0xf9, 0xd1, 0xd9, 0xf4, 0x07, 0xd8, 0x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d1, 0xd9, 0xf8,
    0xf4, 0x1e, 0xd8, 0xf2, 0xf9, 0xd1, 0xd9, 0xf8, 0xf8, 0xf4, 0x14, 0xd8, 0xf4, 0x10, 0xd8, 0xf3,
    /* bank # 5 */
    0xa2, 0xf8, 0xf9, 0xd1, 0xda, 0xf2, 0xa6, 0xf8, 0xf1, 0xa5, 0xde, 0xd8, 0xf4, 0xa3, 0x14, 0x14,
    0xd8, 0xf1, 0xa5, 0xf8, 0xa3, 0x85, 0x95, 0x09, 0xd9, 0xf1, 0xa5, 0xde, 0xf2, 0xa6, 0xf8, 0xdf,
    0xd8, 0xf4, 0xa3, 0x09, 0xd8, 0xf3, 0xa2, 0xf8, 0xf9, 0xd1, 0xf4, 0xd9, 0x08, 0x17, 0xda, 0x42,
    0xf2, 0xa2, 0xde, 0xf4, 0x0b, 0xd8, 0xf1, 0xa5, 0xf8, 0xa3, 0x85, 0x95, 0x19, 0xda, 0xf4, 0x05,
    0xd8, 0xf2, 0xa6, 0xde, 0xdf, 0xd8, 0xf1, 0xb8, 0xaa, 0xb3, 0x8d, 0xb4, 0x98, 0x0d, 0x35, 0x5d,
    0xb2, 0xb6, 0xba, 0xaf, 0x8c, 0x96, 0x19, 0x8f, 0x9f, 0xb8, 0xa8, 0x0e, 0x16, 0x1e, 0xb4, 0x9a,
    0xaa, 0x88, 0x2c, 0x54, 0x7c, 0xd8, 0xf1, 0xb8, 0xb4, 0xb0, 0x97, 0x86, 0xa8, 0x31, 0x9b, 0x06,
    0x99, 0x07, 0xab, 0x97, 0x28, 0x88, 0x9b, 0xf0, 0x0c, 0x20, 0x14, 0x40, 0xb0, 0xb4, 0xb8, 0xf0,
    0xa8, 0x8a, 0x9a, 0x28, 0x50, 0x78, 0xb7, 0x9b, 0xa8, 0x29, 0x51, 0x79, 0x24, 0x70, 0x59, 0x44,
    0x69, 0x38, 0x64, 0x48, 0x31, 0xf1, 0xbb, 0xab, 0x88, 0x00, 0x2c, 0x54, 0x7c, 0xf0, 0xb3, 0x8b,
    0xb8, 0xa8, 0x04, 0x28, 0x50, 0x78, 0xf1, 0xb0, 0x88, 0xb4, 0x97, 0x26, 0xa8, 0x59, 0x98, 0xbb,
    0xab, 0xb3, 0x8b, 0x02, 0x26, 0x46, 0x66, 0xb0, 0xb8, 0xf0, 0x8a, 0x9c, 0xa8, 0x29, 0x51, 0x79,
    0x8b, 0x29, 0x51, 0x8a, 0x24, 0x70, 0x59, 0x8b, 0x20, 0x58, 0x8a, 0x44, 0x69, 0x38, 0x8b, 0x39,
    0x40, 0x8a, 0x64, 0x48, 0x31, 0x8b, 0x30, 0x49, 0x88, 0xf1, 0xac, 0x00, 0x2c, 0x54, 0x7c, 0xf0,
    0x8c, 0xa8, 0x04, 0x28, 0x50, 0x78, 0xf1, 0x88, 0x97, 0x26, 0xa8, 0x59, 0x98, 0xac, 0x8c, 0x02,
    0x26, 0x46, 0x66, 0xf0, 0x89, 0x9c, 0xa8, 0x29, 0x51, 0x79, 0x24, 0x70, 0x59, 0x44, 0x69, 0x38,
    /* bank # 6 */
    0x64, 0x48, 0x31, 0xa9, 0x88, 0x09, 0x20, 0x59, 0x70, 0xab, 0x11, 0x38, 0x40, 0x69, 0xa8, 0x19,
    0x31, 0x48, 0x60, 0x8c, 0xa8, 0x3c, 0x41, 0x5c, 0x20, 0x7c, 0x00, 0xf1, 0x87, 0x98, 0x19, 0x86,
    0xa8, 0x6e, 0x76, 0x7e, 0xa9, 0x99, 0x88, 0x2d, 0x55, 0x7d, 0xd8, 0xf1, 0xb3, 0x8b, 0xb4, 0x97,
    0xbb, 0xab, 0xf8, 0xf9, 0xb9, 0xa3, 0xda, 0xc3, 0xc5, 0xc7, 0xd9, 0x2d, 0x4d, 0x6d, 0xd8, 0xb0,
    0x8c, 0xb8, 0xac, 0xf8, 0xf9, 0xa8, 0xda, 0xc3, 0xc5, 0xc7, 0xd9, 0x2d, 0x4d, 0x6d, 0xd8, 0xf3,
    0xb9, 0xac, 0xde, 0xd8, 0xb1, 0xb6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0x69, 0xd9, 0xf4, 0x07, 0x06, 0xda, 0xf1, 0xb9, 0xab, 0xdf, 0xfe,
    0xd8, 0xf1, 0xbb, 0xb3, 0xb7, 0xaa, 0xf9, 0xda, 0xff, 0xd9, 0x80, 0x9a, 0xaa, 0x28, 0xb4, 0x80,
    0x98, 0xa7, 0x20, 0xd8, 0xb7, 0x87, 0xaa, 0xd0, 0xc1, 0xa7, 0x81, 0x97, 0x62, 0x93, 0xf0, 0x71,
    0x71, 0x60, 0x85, 0x94, 0x01, 0x29, 0x51, 0x79, 0x90, 0xa5, 0xf1, 0x28, 0x4c, 0x6c, 0x87, 0x0c,
    0x95, 0x18, 0x85, 0x78, 0xb0, 0xb4, 0xb8, 0x87, 0x98, 0xaf, 0x20, 0x83, 0x9f, 0x22, 0xb7, 0x93,
    /* bank # 8 */
    0xf0, 0x31, 0x31, 0x20, 0x8e, 0xb4, 0x94, 0x01, 0x29, 0x51, 0x79, 0x97, 0xae, 0xf1, 0x28, 0x4c,
    0x6c, 0x8f, 0x0c, 0x9e, 0x18, 0x8e, 0x78, 0x87, 0x98, 0xaf, 0x20, 0x83, 0x9f, 0x22, 0xb7, 0x93,
    0xf0, 0x31, 0x31, 0x20, 0xb2, 0x81, 0xb4, 0x94, 0x01, 0x9f, 0x29, 0x51, 0x79, 0x97, 0xba, 0xa1,
    0xf1, 0x28, 0x4c, 0x6c, 0xb0, 0x8f, 0x0c, 0xb6, 0x91, 0x18, 0xb2, 0x81, 0x78, 0xb0, 0x87, 0xb4,
    0x98, 0xba, 0xab, 0x20, 0xb2, 0x86, 0xb6, 0x9b, 0x02, 0xb7, 0x93, 0xf0, 0x11, 0x11, 0x00, 0x84,
    0xb6, 0x97, 0x01, 0x29, 0x51, 0x79, 0xb4, 0x97, 0xa4, 0xf1, 0x28, 0x4c, 0x6c, 0x8b, 0x0c, 0xb6,
    0x94, 0x18, 0xb2, 0x84, 0x78, 0xbb, 0xa3, 0xb3, 0x83, 0xb7, 0x90, 0x28, 0x4c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b7, 0x90, 0xb9, 0xa3, 0x69,
    0xdb, 0xb3, 0x80, 0xb5, 0x94, 0x11, 0xd9, 0xf2, 0xa4, 0xd0, 0xde, 0xd8, 0xf2, 0xbb, 0xaf, 0xb7,
    0x92, 0xb3, 0x82, 0x19, 0x80, 0xa2, 0xd9, 0x26, 0xf3, 0xa7, 0xd0, 0xdf, 0xd8, 0xf1, 0xaf, 0x89,
    0x98, 0x19, 0xa9, 0x80, 0xd9, 0x38, 0xd8, 0xaf, 0x89, 0x39, 0xa9, 0x80, 0xda, 0x3c, 0xd8, 0xaf,
    /* bank # 10 */
    0x2e, 0x88, 0xf5, 0x75, 0xda, 0xff, 0xd8, 0x71, 0x80, 0xa9, 0xda, 0xf1, 0xff, 0xd8, 0x82, 0xa7,
    0xf3, 0xc1, 0xf2, 0x80, 0xc2, 0xf1, 0x97, 0x86, 0x49, 0x2e, 0xa6, 0xd0, 0x50, 0x96, 0x86, 0xaf,
    0x75, 0xd9, 0x88, 0xa2, 0xd0, 0xf3, 0xc0, 0xc3, 0xf1, 0xda, 0x8f, 0x96, 0xa2, 0xd0, 0xf3, 0xc2,
    0xc3, 0x82, 0xb4, 0x93, 0x78, 0x78, 0xf1, 0xd8, 0x80, 0xb7, 0x90, 0xaf, 0x0d, 0x89, 0x99, 0xaf,
    0x10, 0x80, 0x9f, 0x21, 0xda, 0x2e, 0xd8, 0x89, 0x99, 0xaf, 0x31, 0x80, 0xda, 0x2e, 0xd8, 0xaf,
    0x82, 0x92, 0xf3, 0x41, 0x80, 0xf1, 0xd9, 0x2e, 0xd8, 0xaf, 0x82, 0xf3, 0x19, 0x80, 0xf1, 0xd9,
    0x2e, 0xd8, 0xf1, 0x89, 0x90, 0xaf, 0xd0, 0x09, 0x8f, 0x99, 0xaf, 0x51, 0xdb, 0x89, 0x31, 0xf3,
    0x82, 0x92, 0x19, 0xf2, 0xb1, 0x84, 0xb5, 0x94, 0x71, 0xd9, 0xf1, 0xdf, 0xf9, 0xf2, 0xb9, 0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 0xba,
    0x82, 0x92, 0xab, 0x39, 0xf3, 0xb1, 0x84, 0xb4, 0x97, 0x49, 0xd9, 0xf1, 0xb2, 0xb6, 0x80, 0x90,
    0xa0, 0xd0, 0x5e, 0xf0, 0x92, 0x38, 0xd8, 0xf2, 0xb3, 0x82, 0xb7, 0x92, 0xbb, 0xaf, 0x31, 0xd9,
    0xf1, 0xbb, 0xac, 0xde, 0xd0, 0xde, 0xba, 0xa2, 0xd0, 0xdf, 0xf1, 0xff, 0xd8, 0xf3, 0xb9, 0xa4,
    0xd0, 0xf8, 0xf9, 0xd1, 0xd9, 0xf2, 0xbb, 0xa2, 0xfa, 0xf8, 0xda, 0xf2, 0xbb, 0xa2, 0xfa, 0xd8,
    0xf2, 0xb3, 0xb7, 0xbb, 0x80, 0x92, 0xaf, 0x49, 0xd1, 0xd9, 0xf1, 0xb9, 0xa4, 0xde, 0xa0, 0xde,
    0xdf, 0xd8, 0xf1, 0x8c, 0x9c, 0xbb, 0xac, 0xd0, 0x10, 0xac, 0xde, 0xba, 0xa2, 0xd0, 0xdf, 0xbb,
    0x92, 0x82, 0xaf, 0xf1, 0xca, 0xf2, 0x35, 0xf1, 0x96, 0x8f, 0xa6, 0xd9, 0x00, 0xd8, 0xff
};

#define DMP_VERSION (dmpMemory)

inv_error_t inv_write_dmp_data(FILE *fd, const unsigned char *dmp, size_t len)
{
    inv_error_t result = INV_SUCCESS;
    int bytesWritten = 0;

    if (len <= 0) {
        MPL_LOGE("Nothing to write");
        return INV_ERROR_FILE_WRITE;
    }
    else {
        MPL_LOGI("dmp firmware size to write = %d", len);
    }
    if ( fd == NULL ) {
        return INV_ERROR_FILE_OPEN;
    }
    bytesWritten = fwrite(dmp, 1, len, fd);
    if (bytesWritten != len) {
        MPL_LOGE("bytes written (%d) don't match requested length (%d)\n",
                 bytesWritten, len);
        result = INV_ERROR_FILE_WRITE;
    }
    else {
        MPL_LOGI("Bytes written = %d", bytesWritten);
    }
    return result;
}

inv_error_t inv_load_dmp(FILE *fd)
{
    inv_error_t result = INV_SUCCESS;
    result = inv_write_dmp_data(fd, DMP_VERSION, DMP_CODE_SIZE);
    return result;
}

void read_dmp_img(char *dmp_path, char* out_file)
{
    MPL_LOGI("read_dmp_img");
    FILE *fp;
    int i;
    int dmpSize = DMP_CODE_SIZE;
    char dmp_img[dmpSize];

    if ((fp = fopen(dmp_path, "rb")) < 0) {
        perror("dmp fail");
    }
    i = fread(dmp_img, 1, dmpSize, fp);
    MPL_LOGI("Result=%d", i);
    fclose(fp);
    fp = fopen(out_file, "wt");
    if(fp == NULL) {
    MPL_LOGE("error open out file:%s", out_file);
        return;
    }
    fprintf(fp, "char rec[]={\n");
    for(i = 0; i < dmpSize; i++) {
        fprintf(fp, "0x%02x, ", dmp_img[i]);
        if(((i + 1) % 16) == 0) {
            fprintf(fp, "\n");
        }
    }
    fprintf(fp, "};\n ");
    fclose(fp);
}

/**
 *  @}
 */
